﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entidades;
using System.Data.OracleClient;
using System.Data;
using System.Configuration;

namespace Datos
{
    public class HistorialServicioAD
    {

        public static int NuevoServicio(HistorialServicio historialservicio)
        {
            OracleConnection oraConn = new OracleConnection();
            int k = 0;
            string connString = "Server=XE;Uid=juan;Pwd=lagartija";
            if (oraConn.State != ConnectionState.Open)
            {
                try
                {
                    oraConn.ConnectionString = connString;

                    oraConn.Open();

                    Console.WriteLine(oraConn.ConnectionString, "Successful Connection");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message, "Exception Caught");
                }
            }

            if (oraConn.State == ConnectionState.Open)
            {
                string sqlInsert = "insert into historial_servicio ";
                sqlInsert += "values (sequence_historial_servicio.nextval, :p_nombreservicio, :p_valor, :p_fecha)";

                OracleCommand cmdInsert = new OracleCommand();
                cmdInsert.CommandText = sqlInsert;
                cmdInsert.Connection = oraConn;

                OracleParameter pNombreServicio = new OracleParameter();
                pNombreServicio.Value = historialservicio.NombreServicio;
                pNombreServicio.ParameterName = "p_nombreservicio";

                OracleParameter pValor = new OracleParameter();
                pValor.DbType = DbType.Int32;
                pValor.Value = Convert.ToInt32(historialservicio.valor);
                pValor.ParameterName = "p_valor";

                OracleParameter pFecha = new OracleParameter();
                pFecha.Value = historialservicio.fecha;
                pFecha.ParameterName = "p_fecha";

               





                cmdInsert.Parameters.Add(pNombreServicio);
                cmdInsert.Parameters.Add(pValor);
                cmdInsert.Parameters.Add(pFecha);
               

                try
                {
                    k = cmdInsert.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message, "Exception Caught");
                }

                cmdInsert.Dispose();







            } return k;
        }
    }
}
